<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/swiper@8/swiper-bundle.css">
    <script src="https://unpkg.com/swiper@8/swiper-bundle.js"> </script>
    <style>
        .kerwin {
            width: 600px;
            height: 300px;
            background: yellow;
        }
    </style>
</head>

<body>
    <div id="box">
        <div class="swiper-container kerwin">
            <div class="swiper-wrapper">
                <div class="swiper-slide" v-for="data in datalist">
                    {{data}}
                </div>
            </div>
            <div class="swiper-pagination"></div>
        </div>
    </div>

    <script type="text/javascript">
        var vm = new Vue({
            el: "#box",
            data: {
                datalist: [],
            },
            mounted() {
                setTimeout(() => {
                    this.datalist = ["aaa", "bbb", "ccc"]
                    //此时属性刚刚挂载完毕，DOM是异步的
                    console.log("mouted", document.querySelectorAll(".swiper-slide").length)

                }, 2000)
            },
            updated() {
                console.log("updated", document.querySelectorAll(".swiper-slide").length)
                new Swiper(".kerwin", {
                    loop: true, //水平轮播
                    // direction: "vertical" //垂直轮播
                    navigation: {
                        nextE1: '.swiper-button-next',
                        prevE1: '.swiper-button-prev',
                    },
                    pagination: {
                        el: ".swiper-pagination",
                    },

                })
            }
        })
    </script>
</body>

</html>